package com.demo.alipay.study.vo;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lvfeilong
 */
@Data
public class ResultResponse {

    private Boolean success;

    private Integer code;

    private String message;

    private Map<String, Object> data = new HashMap<String, Object>();

    private ResultResponse() {
    }

    public static ResultResponse ok() {
        ResultResponse r = new ResultResponse();
        r.setSuccess(ResultCodeEnum.SUCCESS.getSuccess());
        r.setCode(ResultCodeEnum.SUCCESS.getCode());
        r.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        return r;
    }

    public static ResultResponse error() {
        ResultResponse r = new ResultResponse();
        r.setSuccess(ResultCodeEnum.UNKNOWN_REASON.getSuccess());
        r.setCode(ResultCodeEnum.UNKNOWN_REASON.getCode());
        r.setMessage(ResultCodeEnum.UNKNOWN_REASON.getMessage());
        return r;
    }

    public static ResultResponse setResult(ResultCodeEnum resultCodeEnum) {
        ResultResponse r = new ResultResponse();
        r.setSuccess(resultCodeEnum.getSuccess());
        r.setCode(resultCodeEnum.getCode());
        r.setMessage(resultCodeEnum.getMessage());
        return r;
    }

    public ResultResponse success(Boolean success) {
        this.setSuccess(success);
        return this;
    }

    public ResultResponse message(String message) {
        this.setMessage(message);
        return this;
    }

    public ResultResponse code(Integer code) {
        this.setCode(code);
        return this;
    }

    public ResultResponse data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

    public ResultResponse data(Map<String, Object> map) {
        this.setData(map);
        return this;
    }
}